if (!jsx3.lang.Class.forName("ux.cdb.admin.loan.offerLoan.OfferLoan")) {
    /**
     * Define the <code>name of class</code> class.
     * This class inherit from <code>jsx3.gui.Block<code> GUI class.
     */
    jsx3.Class.defineClass(
            "ux.cdb.admin.loan.offerLoan.OfferLoan",
            ux.megatron.gui.Block,
            null,
            function (objRoot) {
                objRoot.prototype.notSavedIds = new Array();
                objRoot.prototype.cloneData = null;
                /**
                 * This method will be called after UI file has deserialized.
                 */
                objRoot.prototype.getPrivilege = function(code) {
                    return ux.cdb.admin.Privilege.getPrivilege(code);
                };
                objRoot.prototype.initUI = function() {
                    if(this.getPrivilege(40)){
                        this.getDescendantOfName("btn_Edit").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    } else {
                        this.getDescendantOfName("btn_Edit").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    }
                    this.getDescendantOfName("btn_Edit").setEnabled(jsx3.gui.Form.STATEDISABLED);
                    this.getDescendantOfName("btn_Save").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("btn_Cancel").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("pan_NoOfferSelected").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.getDescendantOfName("pan_OfferDetails").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.editMode = false;
                };
                objRoot.prototype.loadPageControler = function() {
                    if (!this.pageControlInit) {
                        this.pageCtrler.initialize();
                        this.pageControlInit = true;
                    }
                    this.pageCtrler.setValue(this.currentPage, this.totalPages, this.defaultPageSize, this.totalRecordCount);
                    this.pageCtrler.bindWithMatrix(this, this.onPageChange, this.getMatrix());
                }
                objRoot.prototype.onPageChange = function(msg) {
                    this.currentPage = msg.currentPageNumber;
                    this.getDistributionStatusList();
                }
                objRoot.prototype.getDistributionStatusList = function() {
                    ux.megatron.util.Dwr.callDwr("RetailStudentLoanDistributionStatusUCC", "getDistributionStatusList", [this.searchWord, this.currentPage, this.defaultPageSize, this.status], this, function(dwrObject){
                        this.totalRecordCount = dwrObject.content.page.count;
                        this.loadPageControler();
                        dwrObject = dwrObject.content.data;
                        if(dwrObject.length == 0){
                            this.getDescendantOfName("btn_Edit").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                        } else {
                            this.getDescendantOfName("btn_Edit").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                        }
                        var cdfDoc = ux.megatron.util.Dwr.toCdfDocument(dwrObject, "jsxroot", {}, {"batchApproveInfoId": "jsxid"});
                        this.getServer().getCache().setDocument(this.getMatrix().getXMLId(), cdfDoc);
                        this.getMatrix().repaint();
                    }, "RetailStudentLoanDistributionStatusUCC");
                };
                objRoot.prototype.onAfterDeserialize = function() {
                    try{
                        this.initUI();
                        this.status = 12;
                        this.searchWord = null;
                        this.pageCtrler = this.get("blkPageWheel");
                        this.defaultPageSize = 15;
                        this.totalRecordCount = 0;
                        this.currentPage = 1;
                        this.pageControlInit = false;
                        this.totalPages = 0;
                        this.loadPageControler();
                        this.getDistributionStatusList();
                    } catch(ex) {
                        console.log(ex);
                    }
                };
                objRoot.prototype.getMatrix = function() {
                    return this.getDescendantOfName("mtxMain");
                };
                objRoot.prototype.onRefreshClicked = function() {
                    this.getDistributionStatusList();
                };
                objRoot.prototype.onBeforeEdit = function(objMtx, objEVENT, strRECORDID, objCOLUMN){
                    return this.editMode;
                };
                objRoot.prototype.onAfterEdit = function(objMtx, objEVENT, strRECORDID, objCOLUMN, strNEWVALUE){
                    if(this.notSavedIds.indexOf(strRECORDID) == -1)
                        this.notSavedIds.push(strRECORDID);
                    return strNEWVALUE;
                };
                objRoot.prototype.onEditClicked = function(objBtn, objEVENT){
                    this.cloneData = this.getServer().getCache().getDocument(this.getMatrix().getXMLId()).toString();
                    this.editMode = true;
                    this.showEdit();
                };
                objRoot.prototype.onSaveClicked = function(objBtn, objEVENT){
                    this.editMode = false;
                    var id = null;
                    var saveRecords = new Array();
/* @JSC :: begin DEBUG */
					console.log('notSavedIds : ', this.notSavedIds);
/* @JSC :: end */
                    while(id = this.notSavedIds.pop()){
						var record = this.getMatrix().getRecord(id);
						//var record = this.getMatrix().selectSingleNode('//record[@jsxid=' + id + ']');
/* @JSC :: begin DEBUG */
						console.log('notSavedId : ', id);
						console.log('record : ', record);
/* @JSC :: end */
						record["virtualApproveObjectId"] =  0 + record["virtualApproveObjectId"];
						/*************************************************************************
						 *make sure to return a date object;*/
						var dateTransfer = function(dateString){
							var time = null;
							if(parseInt(dateString)){
								time = dateString;
							} else {
								time = Date.parse(dateString);
							}
							var objDate = new Date();
							if(isNaN(time)){
								return null;
							} else {
								objDate.setTime(time);
								return objDate;
							}
						}
						/****************************************************************************/
						record["contractCommencementDate"] = dateTransfer(record["contractCommencementDate"]);
						record["aidCentreDistributedDate"] = dateTransfer(record["aidCentreDistributedDate"]);
						record["studentDistributedDate"] = dateTransfer(record["studentDistributedDate"]);
						record["approveDate"] = dateTransfer(record["approveDate"]);
						record["appDate"] = dateTransfer(record["appDate"]);
						record["appStartDate"] = dateTransfer(record["appStartDate"]);
						record["approveStartDate"] = dateTransfer(record["approveStartDate"]);
						record["appMaturityDate"] = dateTransfer(record["appMaturityDate"]);
						record["approveMaturityDate"] = dateTransfer(record["approveMaturityDate"]);
						record["contractStartDate"] = dateTransfer(record["contractStartDate"]);
						record["contractEndDate"] = dateTransfer(record["contractEndDate"]);
				
						var result = new objRoot.BatchApproveRepayPlanUIO();
						for(var o in record){
							result[o] = null;
							result[o] = record[o];
						}
/* @JSC :: begin DEBUG */
						console.log('objRoot.BatchApproveRepayPlanUIO : \n', result);
/* @JSC :: end */
                        saveRecords.push(result);
						/* for(var o in objRoot.BatchApproveRepayPlanUIO)
							objRoot.BatchApproveRepayPlanUIO[o] = null; */
                    };
                    ux.megatron.util.Dwr.callDwr("RetailStudentLoanDistributionStatusUCC", "saveBatchDistributionStatus", [saveRecords], this, function(dwrObject){
						this.getDistributionStatusList();
                    }, "RetailStudentLoanDistributionStatusUCC");
                    this.hideEdit();
                };
                objRoot.prototype.doSave = function(objOffer){

                };
                objRoot.prototype.onCancelClicked = function(objBtn, objEvent){
                    this.editMode = false;
                    this.notSavedIds = new Array();
                    this.getServer().getCache().getDocument(this.getMatrix().getXMLId()).loadXML(this.cloneData);
                    this.getMatrix().repaint();
                    this.cloneData = null;
                    this.hideEdit();
                };
                objRoot.prototype.showEdit = function(){
                    this.getDescendantOfName("btn_Edit").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("btn_Save").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.getDescendantOfName("btn_Cancel").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                };
                objRoot.prototype.hideEdit = function(){
                    this.getDescendantOfName("btn_Edit").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.getDescendantOfName("btn_Save").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("btn_Cancel").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                };
                objRoot.prototype.onSearchClicked = function(objBtn, objEVENT) {
                    this.searchWord = this.getDescendantOfName("searchWord").getValue() ? this.getDescendantOfName("searchWord").getValue() : null;
                    this.currentPage = 1;
                    this.getDistributionStatusList();
                };
                objRoot.prototype.onStatusSelected = function(objSel, objEVENT, strRECORDID){
                    this.status = strRECORDID;
                    this.currentPage = 1;
                    this.getDistributionStatusList();
                };
                objRoot.prototype.onOfferSelected = function(objMtx, objEVENT, strRECORDID){
                    if(strRECORDID){
                        this.showOfferDetails(strRECORDID);
                    } else {
                        this.hideOfferDetails();
                    }
                };
                objRoot.prototype.hideOfferDetails = function(){
                    this.getDescendantOfName("pan_NoOfferSelected").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.getDescendantOfName("pan_OfferDetails").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                };
                objRoot.prototype.showOfferDetails = function(strRECORDID){
                    this.getDescendantOfName("pan_NoOfferSelected").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("pan_OfferDetails").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    var me = this;
                    var _showOfferDetails = function(){
                        try{
                            me.getDescendantsOfType("ux.cdb.admin.loan.offerLoan.OfferLoanDetails")[0].loadDetail(me.status, strRECORDID);
                        } catch(ex) {
                        }
                    };
                    if(!this.getDescendantOfName("blk_OfferDetails")){
                        this.loadOfferDetails(_showOfferDetails);
                    } else {
                        this.getDescendantOfName("pan_OfferDetails").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                        _showOfferDetails();
                    }
                };
                objRoot.prototype.loadOfferDetails = function(callback){
                    var me = this;
                    ux.megatron.Main.loadUIResourceAsync(this.getDescendantOfName("pan_OfferDetails"), "ux.cdb.admin", "ux/cdb/admin/loan/offerLoan/ui/OfferLoanDetails.xml", me, callback);
                };
                objRoot.BatchApproveRepayPlanUIO = function(){
					this.partyId = null;
					this.orgLevelCode = null;
					this.contractEndDate = null;
					this.loanEvalRptNbr = null;
					this.approveTotalAmt = null;
					this.parentBatchApproveInfoId = null;
					this.approvePeriod = null;
					this.appPropertyCode = null;
					this.coreBankingLoanNbr = null;
					this.appDate = null;
					this.virtualApproveObjectId = null;
					this.approveDate = null;
					this.appStudentCount = null;
					this.cooperAgreementNbr = null;
					this.approveMaturityDate = null;
					this.appMaturityDate = null;
					this.approveConclusionCode = null;
					this.loanConfirmationStatusCode = null;
					this.appCurrencyCode = null;
					this.approveStartDate = null;
					this.approveFileNbr = null;
					this.appPeriod = null;
					this.aidCentreDistributedDate = null;
					this.concentrateApproveInfoId = null;
					this.approveCurrencyCode = null;
					this.appStartDate = null;
					this.contractCommencementDate = null;
					this.approveMeetingNbr = null;
					this.studentDistributedDate = null;
					this.projectStatusCode = null;
					this.batchApproveInfoId = null;
					this.contractStartDate = null;
					this.appPeriodUnitCode = null;
					this.issueAppUserId = null;
					this.approveExcercisingIntRate = null;
					this.appTotalAmt = null;
					this.appName = null;
					this.appExchangeRate = null;
					this.projectStatusName = null;
					this.approvePeriodUnitCode = null;
					this.partyName = null;
					this.internalOrgId = null;
					this.approveExchangeRate = null;
				}
            }
    )
}